package game.objects.nonstaticObjects;

import engine.game.Manager;
import engine.graphics.Color4f;
import engine.objects.EBouncing;
import engine.objects.PhysicsObject;
import game.item.Item;

public class ItemModel extends PhysicsObject {

	private static final long serialVersionUID = 1L;

	public static final String ITEM_ANIM_NAME = "items";
	
	private final Item item  ; 

	private boolean isPickedUp = false ; 
	private EntityModel entity ; 
	
	public ItemModel(Manager m, int x, int y, int w, int h, Item item) {
		super(m, x, y, w, h, true);
		this.item = item ; 
		this.enableBouncing(EBouncing.MEDIUM); 
		this.changeColor(new Color4f(0.85f, 0.85f, 0.85f, 1)) ; 
	}
	
	public Item getItem(){
		return this.item ; 
	}

	public void pickUp(EntityModel entity) {
		this.stopAllTimers(); 
		this.getManager().remove(this); 
		this.isPickedUp = true ; 
		this.entity = entity ; 
	}

	public boolean isPickedUp() {
		return this.isPickedUp; 
	}

	public EntityModel wasPickedUpBy(){
		return this.entity ; 
	}
	
	public void drop() {
		this.changeLocation((int)this.entity.getMinX(), (int)this.entity.getMaxY());
		this.getManager().addNewObject(this);
		this.continueAllTimers(); 
		this.isPickedUp = false  ; 
		this.entity = null ; 
	}
	public void update(){
		if(!this.isPickedUp()){
			this.item.update(); 
			super.update(); 
		}
	}

	
}
